package org.ouwa.lms.client.model;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 * An account representing the registered users of the application.
 * 
 * @author lviet
 */
@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Account implements Serializable {
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	protected Long id;
	@Persistent
	protected String name;
	@Persistent
	protected String email;
	
	public Account() {
		this(null, null);
	}
	
	public Account(String name, String email) {
		this.name = name;
		this.email = email;
	}
	
	public Account(Account account) {
		this(account.getName(), account.getEmailAddress());
	}
	
	//=============================== Getters/Setters ===============================
	
	public String getEmailAddress() {
		return email;
	}
	/*
	public void setEmail(String email) {
		this.email = email;
	}
	*/
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public Long getId() {
		return id;
	}
	
	//=============================== Object Methods ===============================
	
	@Override
    public String toString() {
        return new StringBuffer("Account[")
                .append("name='").append(getName()).append("', ")
                .append("email='").append(getEmailAddress()).append("', ")
                .append("id='").append(getId()).append("'")
                .append("]")
                .toString();
	}
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Account)) return false;
        
        Account account = (Account) o;
        if (id != account.id) return false;
        if (!email.equals(account.email)) return false;
        if (!name.equals(account.name)) return false;
        
        return true;
    }
    
    @Override
    public int hashCode() {
        int result;
        result = id.hashCode();
        result = 31 * result + name.hashCode();
        result = 31 * result + email.hashCode();
        
        return result;
    }
}
